﻿using System;
using System.Data;
using Npgsql;
using ADO.Beans.Beans.Class;

namespace ADO.DataAccess.DAO.CLASS
{
    public class DaoPersona
    {
        //private VoPersona miPersona = new VoPersona();
        private readonly Conexion miConexion = new Conexion();
        private NpgsqlCommand miComando;
        private readonly DataSet miDataSet = new DAO.DataSets.dsPersona();
        private NpgsqlDataAdapter miAdapter;
        private readonly string sqlInsert = 
            String.Format("Insert Into {0}PERSONA{0} Values(@nitPersona, @nombrePersona)", '"');
        private readonly string sqlSelect = String.Format("Select * From {0}PERSONA{0}", '"');
        private readonly string personaStr = String.Format("{0}PERSONA{0}", '"');

        public void InsertarPersona(VoPersona persona)
        {
            miComando = new NpgsqlCommand(sqlInsert, miConexion.MiConexion);
            miComando.Parameters.AddWithValue("@nitPersona", persona.Cedula);
            miComando.Parameters.AddWithValue("@nombrePersona", persona.Nombre);
            miConexion.MiConexion.Open();
            miComando.ExecuteNonQuery();
            miConexion.MiConexion.Close();
        }

        public DataSet ListadoPersonas()
        {
            miAdapter = new NpgsqlDataAdapter(sqlSelect, miConexion.MiConexion);
            miConexion.MiConexion.Open();
            miAdapter.Fill(miDataSet, "PERSONA");
            miConexion.MiConexion.Close();
            return miDataSet;
        }
    }
}